import axios from "axios";
import { apiUrl } from "@/common/corewebapi/index";
import { useAxiosStore } from '@/store/axios'

export const service = axios.create({ baseURL: apiUrl() })

//请求拦截器---在axios发起请求之前要做的事(aop思想)
service.interceptors.request.use(config => {
    //这里就是配置axios请求的时候带上token    
    config.headers.Authorization = 'Bearer ' + useAxiosStore().accessToken;

    return config;
});

//响应拦截器---在axios响应后要做的事
service.interceptors.response.use(async response => {
    return response;
});